/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#chaxtj-fjflb-chaxunbtn").trigger('click'); 
		return false;
		}
	});
});
var kaishisj ='';
var jieshusj ='';
var mingcheng = '';
var xiangmulx = 4;
//初始时间获取方法
function getShijian(prekaishisj,prejieshusj){
		//重置按钮
	$('#chaxtj-fjflb-chongzhibtn').click(function(){
		$('#fjf-kaishjsj').val(prekaishisj);
		$('#fjf-jieshusj').val(prejieshusj);
		$('#chaxtj-fjflb-mingcheng').val('');
		$('#chaxtj-fjflxcanshu').val(1);
//		重置后进行查询
		if(prekaishisj!=null){
		kaishisj=prekaishisj;
		jieshusj=prejieshusj;
		mingcheng='';
		$('#chaxtj-fjfhzlbnr').css('display','none');
		$('#lx-fjfmx').addClass('xuanzong');
		$('#lx-fjfhz').removeClass('xuanzong');
		getMxFjf();
	}
	});
	if(prekaishisj!=null){
		kaishisj=prekaishisj;
		jieshusj=prejieshusj;
		mingcheng='';
		$('#lx-fjfmx').addClass('xuanzong');
		getMxFjf();
	}
}

//查询按钮
$('#chaxtj-fjflb-chaxunbtn').click(function(){
	kaishisj=$('#fjf-kaishjsj').val();
	jieshusj=$('#fjf-jieshusj').val();
	mingcheng=$('#chaxtj-fjflb-mingcheng').val();
	var chaxunlx=$('#chaxtj-fjflxcanshu').val();
	if(chaxunlx==1){
		$('#chaxtj-fjfhzlbnr').css('display','none');
		getMxFjf();
	}else if(chaxunlx==2){
		$('#chaxtj-fjfmxlbnr').css('display','none');
		getHzFjf();
	}
});
//查询类别,切换后直接进行查询
$('.fujiafy ul li').on('click',function(){
	$(this).addClass('xuanzong');
	$(this).siblings('li').removeClass('xuanzong');
	$('#chaxtj-fjflxcanshu').val($(this).val());
	var chaxunlx=$('#chaxtj-fjflxcanshu').val();
	//查询传值
	kaishisj=$('#fjf-kaishjsj').val();
	jieshusj=$('#fjf-jieshusj').val();
	mingcheng=$('#chaxtj-fjflb-mingcheng').val();
	if(chaxunlx==1){
		$('#chaxtj-fjfhzlbnr').css('display','none');
		getMxFjf();
	}else if(chaxunlx==2){
		$('#chaxtj-fjfmxlbnr').css('display','none');
		getHzFjf();
	}
});

//hz
function getHzFjf(){
	var totalNumber = 0;
	var params={
			'kaishisj':kaishisj,
		    'jieshusj':jieshusj,
		    'mingcheng':mingcheng,
		    'xiangmulx':xiangmulx,
		};
		$.ajax({
		    type:"POST",
		    url:"../chaxuntjjcxfjf/getHzCount",
		    data:params,
		    async:false,
		    success: function(data){
		    	if(data!=null) {
		    		totalNumber = data;
				}
		    	if(totalNumber==0){
					$("#chaxtj-fjfhzlbnr").css("display","none");
					$("#chaxtj-fjf-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
				}else{
					$("#chaxtj-fjfhzlbnr").css("display","block");
					$("#chaxtj-fjf-img").html("");
				}
			}
		});
	function createHzFjf(name) {
	$('#tb-chaxtjfjfhz').html('');
	  var container = $('#pagination-'+name);
	  container.pagination({
	    dataSource:'../chaxuntjjcxfjf/getHzByPage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&mingcheng='+mingcheng+'&xiangmulx='+xiangmulx,
	    locator: 'entities',
	    pageSize: 12,
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
	    totalNumber: totalNumber,
	    callback: function(data, pagination) {
	    	if(data!='') {
				var content = '';
				$(data).each(function(index,e){
					if(this.danwei==null){
			  			var danwei='';
		  			}else{
						var danwei=this.danwei;
		 			 }
					content += '<tr>'+
					'<td width="5%">'+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+'</td>'+
	                '<td width="50%" class="left">'+this.mingcheng+'</td>'+
	                '<td width="25%">'+this.xiaoshousl+danwei+'</td>'+
	                '<td width="20%" class="right">'+parseFloat(this.xiaoshouje).toFixed(2)+'</td>'+
	                '</tr>';
				});
				$('#tb-chaxtjfjfhz').html(content);
	    	}
	    }
	  });
	  return container;
	}
	createHzFjf('fenyfjfhz');
	if(totalNumber <= 12) {
		$('#pagination-fenyfjfhz').css('display','none');
	}else{
		$('#pagination-fenyfjfhz').css('display','block');
	}
}


	function getMxFjf(){
	var totalNumber = 0;
	var params={
			'kaishisj':kaishisj,
		    'jieshusj':jieshusj,
		    'mingcheng':mingcheng,
		    'xiangmulx':xiangmulx,
		};
		$.ajax({
		    type:"POST",
		    url:"../chaxuntjjcxfjf/getMxCount",
		    data:params,
		    async:false,
		    success: function(data){
		    	if(data!=null) {
		    		totalNumber = data;
				}
		    	if(totalNumber==0){
					$("#chaxtj-fjfmxlbnr").css("display","none");
					$("#chaxtj-fjf-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
				}else{
					$("#chaxtj-fjfmxlbnr").css("display","block");
					$("#chaxtj-fjf-img").html("");
				}
			}
		});
	function createMxFjf(name) {
	  $('#tb-chaxtjfjfmx').html('');
	  var container = $('#pagination-'+name);
	  container.pagination({
	    dataSource:'../chaxuntjjcxfjf/getMxByPage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&mingcheng='+mingcheng+'&xiangmulx='+xiangmulx,
	    locator: 'entities',
	    pageSize: 12,
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
	    totalNumber: totalNumber,
	    callback: function(data, pagination) {
	    	if(data!='') {
				var content = '';
				$(data).each(function(index,e){
					if(this.danwei==null){
			  			var danwei='';
		  			}else{
						var danwei=this.danwei;
		 			 }
					content += '<tr>'+
					'<td width="5%">'+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+'</td>'+
	                '<td width="30%" class="left">'+this.mingcheng+'</td>'+
	                '<td width="20%" class="left">'+this.xingming+'</td>'+
	                '<td width="10%">'+this.shoufeirq+'</td>'+
	                '<td width="20%">'+this.xiaoshousl+danwei+'</td>'+
	                '<td width="15%" class=" right">'+parseFloat(this.xiaoshouje).toFixed(2)+'</td>'+
	                '</tr>';
				});
				$('#tb-chaxtjfjfmx').html(content);
	    	}
	    }
	  });
	  return container;
	}
	createMxFjf('fenyfjfmx');
	if(totalNumber <= 12) {
		$('#pagination-fenyfjfmx').css('display','none');
	}else{
		$('#pagination-fenyfjfmx').css('display','block');
	}
}